package cn.lbd.lock;

import java.util.concurrent.TimeUnit;

public class TicketSeller {
    public void sell() {
        try {
            System.out.println("售票开始...");
            TimeUnit.SECONDS.sleep(5);
            System.out.println("售票结束...");
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void sellTicketWithLock() {
        MyLock lock = new MyLock();
        lock.lock();
        sell();
        lock.unlock();
    }

    public static void main(String[] args) {
        TicketSeller seller = new TicketSeller();
        for (int i = 0; i < 5; i++) {
            seller.sellTicketWithLock();
        }
    }
}
